home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 042a / swagn_r.zip / POINTERS.SWG < prev    next >
Text File  |  1993-05-28  |  28KB  |  1 lines

  1. SWAGOLX.EXE (c) 1993 GDSOFT  ALL RIGHTS RESERVED 00008         POINTERS, LINKING, LISTS, TREES                                   1      05-28-9313:54ALL                      SWAG SUPPORT TEAM        DLLIST1.PAS              IMPORT              9           { > Does anybody have any good source/Units For Turboπ > Pascal 6.0/7.0 For doing Double Linked List Fileπ > structures?π}ππTypeππ   DLinkPtr = ^DLinkRecord;ππ   DLinkRecord = Recordπ      Data     : Integer;π      Next     : DLinkPtr;π      Last     : DLinkPtr;π     end;ππVarπ  Current,π  First,π  Final,π  Prev    : DLinkPtr;π  X       : Byte;ππProcedure AddNode;πbeginπ  if First = Nil thenπ   beginπ     New(Current);π     Current^.Next:=Nil;π     Current^.Last:=Nil;π     Current^.Data:=32;π     First:=Current;π     Final:=Current;π   endπ  elseπ   beginπ    Prev:=Current;π    New(Current);π    Current^.Next:=Nil;π    Current^.Last:=Prev;π    Current^.Data:=54;π    Prev^.Next:=Current;π    Final:=Current;π   end;πend;ππbeginπ  First:=Nil;π  For X:=1 to 10 Do AddNode;π  Writeln('First: ',first^.data);π  Writeln('Final: ',final^.data);π  Writeln('Others:');π  Writeln(first^.next^.data);ππend.π                                                                                                                       2      05-28-9313:54ALL                      SWAG SUPPORT TEAM        LINKLIST.PAS             IMPORT              63          {πThe following is the LinkList Unit written by Peter Davis in his wonderfulπbut, unFortunately, short-lived newsletter # PNL002.ZIP.  I have used thisπUnit to Write tests of three or four of the Procedures but have stumped my toeπon his DELETE_HERE Procedure, the last one in the Unit.  I will post my testsπin the next message For any who may wish to see it:  Pete's Unit is unmodified.π I almost think there is some kind of error in DELETE_HERE but he was tooπthorough For that.  Can you, or someone seeing this show me how to use thisπProcedure?  It will help me both With Pointers and With Units.ππHere is the Unit:π}ππUnit LinkList;ππ{ This is the linked list Unit acCompanying The Pascal NewsLetter, Issue #2.π  This Unit is copyrighted by Peter Davis.π  It may be freely distributed in un-modified Form, or modified For use inπ  your own Programs. Programs using any modified or unmodified Form of thisπ(107 min left), (H)elp, More?   Unit must include a run-time and source visible recognition of the author,π  Peter Davis.π}ππ{ The DataType used is Integer, but may be changed to whatever data Typeπ  that you want.π}ππInterfaceπππTypeπ  DataType = Integer;    { Change this data-Type to whatever you want  }ππ  Data_Ptr = ^Data_Rec;  { Pointer to our data Records                 }ππ  Data_Rec = Record      { Our Data Record Format                      }π    OurData  : DataType;π    Next_Rec : Data_Ptr;π  end;πππProcedure Init_List(Var Head : Data_Ptr);πProcedure Insert_begin(Var Head : Data_Ptr; Data_Value : DataType);πProcedure Insert_end(Var Head : Data_Ptr; Data_Value : DataType);πProcedure Insert_In_order(Var Head : Data_Ptr; Data_Value : DataType);πFunction Pop_First(Var Head : Data_Ptr) : DataType;πFunction Pop_Last(Var Head : Data_Ptr) : DataType;πProcedure Delete_Here(Var Head : Data_Ptr; Our_Rec : Data_Ptr);ππππImplementationππProcedure Init_List(Var Head : Data_Ptr);ππbeginπ  Head := nil;πend;ππProcedure Insert_begin(Var Head : Data_Ptr; Data_Value : DataType);ππ{ This Procedure will insert a link and value into theπ  beginning of a linked list.                             }ππVarπ  Temp : Data_Ptr;                { Temporary  Pointer.            }ππbeginπ  new(Temp);                      { Allocate our space in memory.  }π  Temp^.Next_Rec := Head;         { Point to existing list.        }π  Head:= Temp;                    { Move head to new data item.    }π  Head^.OurData := Data_Value;    { Insert Data_Value.             }πend;ππProcedure Insert_end(Var Head : Data_Ptr; Data_Value : DataType);ππ{ This Procedure will insert a link and value into theπ  end of the linked list.                                 }ππVarπ  Temp1,             { This is where we're going to put new data }π  Temp2 : Data_Ptr;  { This is to move through the list.         }ππbeginπ  new(Temp1);π  Temp2 := Head;π  if Head=nil thenπ    beginπ      Head := Temp1;                  { if list is empty, insert first   }π      Head^.OurData := Data_Value;    { and only Record. Add value and   }π      Head^.Next_Rec := nil;          { then put nil in Next_Rec Pointer }π    endπ  elseπ    beginπ      { Go to the end of the list. Since Head is a Variable parameter,π        we can't move it through the list without losing Pointer to theπ        beginning of the list. to fix this, we use a third Variable:π        Temp2.π      }π      While Temp2^.Next_Rec <> nil do    { Find the end of the list. }π        Temp2 := Temp2^.Next_Rec;ππ      Temp2^.Next_Rec := Temp1;          { Insert as last Record.    }π      Temp1^.Next_Rec := nil;            { Put in nil to signify end }π      Temp1^.OurData := Data_Value;      { and, insert the data      }π    end;πend;ππProcedure Insert_In_order(Var Head : Data_Ptr; Data_Value : DataType);ππ{ This Procedure will search through an ordered linked list, findπ  out where the data belongs, and insert it into the list.        }ππVarπ  Current,              { Where we are in the list               }π  Next     : Data_Ptr;  { This is what we insert our data into.  }ππbeginπ  New(Next);π  Current := Head;      { Start at the top of the list.          }ππ  if Head = Nil thenπ    beginπ      Head:= Next;π      Head^.OurData := Data_Value;π      Head^.Next_Rec := Nil;π    endπ  elseπ  { Check to see if it comes beFore the first item in the list   }π  if Data_Value < Current^.OurData thenπ    beginπ      Next^.Next_Rec := Head;      { Make the current first come after Next }π      Head := Next;                { This is our new head of the list       }π      Head^.OurData := Data_Value; { and insert our data value.             }π    endπ  elseπ    beginπ      { Here we need to go through the list, but always looking one stepπ        ahead of where we are, so we can maintain the links. The methodπ        we'll use here is: looking at Current^.Next_Rec^.OurDataπ        A way to explain that in english is "what is the data pointed toπ        by Pointer Next_Rec, in the Record pointed to by Pointerπ        current." You may need to run that through your head a few timesπ        beFore it clicks, but hearing it in English might make it a bitπ        easier For some people to understand.                            }ππ      While (Data_Value >= Current^.Next_Rec^.OurData) andπ            (Current^.Next_Rec <> nil) doπ        Current := Current^.Next_Rec;π      Next^.OurData := Data_Value;π      Next^.Next_Rec := Current^.Next_Rec;π      Current^.Next_Rec := Next;π    end;πend;ππFunction Pop_First(Var Head : Data_Ptr) : DataType;ππ{ Pops the first item off the list and returns the value to the caller. }ππVarπ  Old_Head : Data_Ptr;ππbeginπ  if Head <> nil then   { Is list empty? }π    beginπ      Old_Head := Head;π      Pop_First := Head^.OurData;  { Nope, so Return the value }π      Head := Head^.Next_Rec;      { and increment head.       }π      Dispose(Old_Head);           { Get rid of the old head.  }π    endπ  elseπ    beginπ      Writeln('Error: Tried to pop an empty stack!');π      halt(1);π    end;πend;πππFunction Pop_Last(Var Head : Data_Ptr) : DataType;ππ{ This Function pops the last item off the list and returns theπ  value of DataType to the caller.                              }ππVarπ  Temp : Data_Ptr;ππbeginπ  Temp := Head;       { Start at the beginning of the list. }π  if head = nil then  { Is the list empty? }π    beginπ      Writeln('Error: Tried to pop an empty stack!');π      halt(1);π    endπ  elseπ  if head^.Next_Rec = Nil then { if there is only one item in list, }π    beginπ      Pop_Last := Head^.OurData;  { Return the value               }π      Dispose(Head);              { Return the memory to the heap. }π      Head := Nil;                { and make list empty.           }π    endπ  elseπ    beginπ      While Temp^.Next_Rec^.Next_Rec <> nil do  { otherwise, find the end }π        Temp := Temp^.Next_rec;π      Pop_Last := Temp^.Next_Rec^.OurData;  { Return the value          }π      Dispose(Temp^.Next_Rec);              { Return the memory to heap }π      Temp^.Next_Rec := nil;                { and make new end of list. }π    end;πend;πππProcedure Delete_Here(Var Head : Data_Ptr; Our_Rec : Data_Ptr);πππ{ Deletes the node Our_Rec from the list starting at Head. The Procedureπ  does check For an empty list, but it assumes that Our_Rec IS in the list.π}ππVarπ  Current : Data_Ptr;  { Used to move through the list. }ππbeginπ  Current := Head;π  if Current = nil then   { Is the list empty? }π    beginπ      Writeln('Error: Cant delete from an empty stack.');π      halt(1);π    endπ  elseπ    begin   { Go through list Until we find the one to delete. }π      While Current^.Next_Rec <> Our_Rec doπ        Current := Current^.Next_Rec;π      Current ^.Next_Rec := Our_Rec^.Next_Rec; { Point around old link. }π      Dispose(Our_Rec);                        { Get rid of the link..  }π    end;πend;πππend.π                                                                                                3      05-28-9313:54ALL                      SWAG SUPPORT TEAM        LL-INSRT.PAS             IMPORT              13          {     The following Program yields output that indicates that I have it set upπcorrectly but With my scanty understanding of exactly how to handle a linkedπlist I would be surprised if it is.  This is one difficult area in which Swanπis not quite as expansive as he might be.ππ        I will appreciate critique and commentary on this if you are anybodyπwould be so kind as to give it:π}ππProgram InsertLink;πUses Crt;ππTypeπ  Str15 = String[15];π  Aptr = ^Link;π  Link = Recordπ       Data : Str15;π       Node : Aptr;π  end;ππVarπ  FirstItem, NewItem, OldItem : Aptr;ππProcedure CreateList;πbeginπ  Writeln('Linked list BEForE insertion of node.');π  Writeln;π  New(FirstItem);π  FirstItem^.Data := 'inSERT ';π  Write(FirstItem^.Data);π  Write('             ');π  New(FirstItem^.Node);π  FirstItem^.Node^.Data := 'HERE';π  Writeln(FirstItem^.Node^.Data);π  FirstItem^.Node^.Node := NIL;πend;ππProcedure InsertALink;πbeginπ  Writeln; Writeln;π  Writeln('Linked list AFTER insertion of node.');π  Writeln;π  Write(FirstItem^.Data);π  New(NewItem);π  NewItem^.Node := OldItem^.Node;π  OldItem^.Node := NewItem;π  FirstItem^.Node^.Data := 'inSERTEDLinK';π  Write(FirstItem^.Node^.Data);π  New(FirstItem^.Node^.Node);π  FirstItem^.Node^.Node^.Data := ' HERE';π  Writeln(FirstItem^.Node^.Node^.Data);π  FirstItem^.Node^.Node^.Node := NIL;πend;ππProcedure DisposeList;πbeginπ  Dispose(FirstItem^.Node^.Node);π  FirstItem^.Node := NIL;πend;ππbeginπ  ClrScr;π  CreateList;π  Writeln;π  InsertALink;π  DisposeList;πend.π                        4      05-28-9313:54ALL                      SWAG SUPPORT TEAM        LL_TEST.PAS              IMPORT              20          {πThis is the test Program that I drew up to test the Procedures in PeteπDavis' LinkList.Pas posted in the previous message.  It could be a little moreπdressed up but it does work and offers some insight, I think, into the use ofπPointers and linked lists:  note that I ran a little manual test to locate aπdesignated Pointer in a given list.  Here it is:π}ππUsesπ  Crt, LinkList;ππVarπ  AList1, AList2, AList3, AList4 : Data_Ptr;π  ANum : DataType;π  Count : Integer;ππbeginπ  ClrScr;π  Init_List(AList1);π  Writeln('Results of inserting links at the beginning of a list: ');π  For Count := 1 to 20 doπ  beginπ    ANum := Count;π    Write(' ',ANum);π    Insert_begin(AList1, ANum); {pay out first link (1) to last (20) like}π                                {a fishing line With #-cards.  You end up}π  end;                          {with 20 in your hand going up to 1}π  Writeln;π  Writeln('Watch - Last link inserted is the highest number.');π  Writeln('You are paying out the list like reeling out a fishing line,');π  Writeln('Foot 1, Foot 2, Foot 3, etc. - last one is Foot 20.');π  Writeln('Now, mentally reel in the line to the fourth number.');π  Writeln(' ',alist1^.Next_Rec^.Next_Rec^.Next_Rec^.OurData);π  Writeln;π  Writeln('Now insert one additional number at beginning of list');π  beginπ    ANum := 21;π    Insert_begin(AList1,ANum);π  end;π  Writeln(' ',AList1^.OurData);π   Writeln;πππ  Init_List(Alist2);π  Writeln('Results of Inserting links in turn at the end of a list: ');π  For Count := 1 to 20 doπ  beginπ    ANum := Count;π    Write(' ',ANum);π    Insert_end(Alist2,ANum);π  end;π  Writeln;π  Writeln('note, just the reverse situation of the process above.');π  Writeln('Reel in the line to the fourth number.');π  Writeln(' ',Alist2^.Next_Rec^.Next_Rec^.Next_Rec^.OurData);π          {We inserted at the end so we are now going out toward the 20}ππππ Init_List(Alist3);π Writeln('Results of Inserting links in turn in orDER');π For Count := 1 to 20 doπ beginπ   Anum := Count;π   Write(' ',ANum);π   Insert_In_order(Alist3,ANum);π end;π Writeln;π Writeln(' ',Alist3^.Next_Rec^.Next_Rec^.Next_Rec^.OurData);ππend.π{π        In Case anybody missed Pete Davis' Linklist Unit in the previousπmessage but may have it in her/his library (PNL002.ZIP) what I was asking isπsome help With writing code to test the Procedure DELETE_HERE which is the lastπProcedure in the Unit.π}                                     5      05-28-9313:54ALL                      SWAG SUPPORT TEAM        OOP-LLST.PAS             IMPORT              90          Program Linked;ππTypeπ  FileDescriptor =π    Objectπ      Fpt       : File;π      Name      : String[80];π      HeaderSize: Word;π      RecordSize: Word;π      RecordPtr : Pointer;π      SoftPut   : Boolean;π      IsOpen    : Boolean;π      CurRec    : LongInt;ππ      Constructor Init(Nam : String; Hdr : Word; Size : Word; Buff : Pointer;πPut : Boolean);π      Destructor  Done; Virtual;π      Procedure   OpenFile; Virtual;π      Procedure   CloseFile; Virtual;π      Procedure   GetRecord(Rec : LongInt);π      Procedure   PutRecord(Rec : LongInt);π    end;ππ  FileLable =π    Recordπ      Eof : LongInt;π      MRD : LongInt;π      Act : LongInt;π      Val : LongInt;π      Sync: LongInt;π    end;ππ  LabeledFile =π    Object(FileDescriptor)π      Header : FileLable;ππ      Constructor Init(Nam : String; Size : Word; Buff : Pointer; Put :πBoolean);π      Destructor  Done; Virtual;π      Procedure   OpenFile; Virtual;π      Procedure   CloseFile; Virtual;π      Procedure   WriteHeader;π      Procedure   ReadHeader;π      Procedure   AddRecord;π      Procedure   DelRecord(Rec : LongInt);π    end;ππ  DetailHeaderPtr = ^DetailHeader;π  DetailHeader =π    Recordπ      Master : LongInt;π      Prev   : LongInt;π      Next   : LongInt;π    end;ππ  MasterHeaderPtr = ^MasterHeader;π  MasterHeader =π    Recordπ      First  : LongInt;π      Last   : LongInt;π    end;ππ  DetailFileDetailPtr = ^DetailFileDetail;π  DetailFileDetail =π    Object(LabeledFile)π      Constructor Init(Nam : String; Size : Word; Buff : Pointer; Put :πBoolean);π      Procedure   LinkChain(MR, Last, Curr : LongInt);π      Procedure   DelinkChain(Rec : LongInt);π    end;ππ  DetailFileMaster =π    Object(LabeledFile)π      Constructor Init(Nam : String; Size : Word; Buff : Pointer; Put :πBoolean);π      Procedure   LinkDetail(DF : DetailFileDetailPtr);π      Procedure   DelinkDetail(DF : DetailFileDetailPtr; DR : LongInt);π      Procedure   GetFirst(DF : DetailFileDetailPtr);π      Procedure   GetLast(DF : DetailFileDetailPtr);π      Procedure   GetNext(DF : DetailFileDetailPtr);π      Procedure   GetPrev(DF : DetailFileDetailPtr);π    end;ππ{---------------------------------------------------------------------------}ππConstructor FileDescriptor.Init(Nam : String; Hdr : Word; Size : Word; Buff :π                                Pointer; Put : Boolean);π  beginπ    IsOpen := False;π    Name := Nam;π    HeaderSize := Hdr;π    RecordSize := Size;π    RecordPtr := Buff;π    SoftPut := Put;π    CurRec := -1;π  end;ππDestructor  FileDescriptor.Done;π  beginπ    if SoftPut and (CurRec <> -1) thenπ        PutRecord(CurRec);π    if IsOpen thenπ        CloseFile;π  end;ππProcedure   FileDescriptor.OpenFile;π  beginπ    if IsOpen thenπ        Exit;π    Assign(Fpt,Name);π    {$I-}π    Reset(Fpt,1);π    if IoResult <> 0 thenπ        ReWrite(Fpt,1);π    if IoResult = 0 thenπ        IsOpen := True;π    {$I+}π    CurRec := -1;π  end;ππProcedure   FileDescriptor.CloseFile;π  beginπ    if not IsOpen thenπ        Exit;π    {$I-}π    Close(Fpt);π    if IoResult = 0 thenπ        IsOpen := False;π    {$I+}π    CurRec := -1;π  end;ππProcedure   FileDescriptor.GetRecord(Rec : LongInt);π  Varπ    Result : Word;π  beginπ    if not IsOpen thenπ        Exit;π    if CurRec = Rec thenπ        Exit;π    if SoftPut and (CurRec <> -1) thenπ        PutRecord(CurRec);π    {$I-}π    if Rec = 0 thenπ      beginπ        Seek(Fpt,0);π        if IoResult = 0 thenπ          beginπ            BlockRead(Fpt,RecordPtr^,HeaderSize,Result);π            if (Result <> HeaderSize) or (IoResult <> 0) thenπ                {Error Routine};π          end;π      endπ    elseπ      beginπ        Seek(Fpt,HeaderSize + (Rec - 1) * RecordSize);π        if IoResult = 0 thenπ          beginπ            BlockRead(Fpt,RecordPtr^,RecordSize,Result);π            if (Result <> RecordSize) or (IoResult <> 0) thenπ                {Error Routine};π          end;π      end;π    {$I+}π    CurRec := Rec;π  end;ππProcedure   FileDescriptor.PutRecord(Rec : LongInt);π  Varπ    Result : Word;π  beginπ    if not IsOpen thenπ        Exit;π    {$I-}π    if Rec = 0 thenπ      beginπ        Seek(Fpt,0);π        if IoResult = 0 thenπ          beginπ            BlockWrite(Fpt,RecordPtr^,HeaderSize,Result);π            if (Result <> HeaderSize) or (IoResult <> 0) thenπ                {Error Routine};π          end;π      endπ    elseπ      beginπ        Seek(Fpt,HeaderSize + (Rec - 1) * RecordSize);π        if IoResult = 0 thenπ          beginπ            BlockWrite(Fpt,RecordPtr^,RecordSize,Result);π            if (Result <> RecordSize) or (IoResult <> 0) thenπ                {Error Routine};π          end;π      end;π    CurRec := Rec;π    {$I+}π  end;ππ{---------------------------------------------------------------------------}ππConstructor LabeledFile.Init(Nam : String; Size : Word; Buff : Pointer; Put :πBoolean);π  beginπ    if Size < 4 thenπ      beginπ        WriteLN('Record size must be 4 or larger');π        Fail;π      end;π    FileDescriptor.Init(Nam,Sizeof(Header),Size,Buff,Put);π    Header.Eof := 0;π    Header.MRD := 0;π    Header.Act := 0;π    Header.Val := 0;π    Header.Sync:= 0;π  end;ππDestructor LabeledFile.Done;π  beginπ    CloseFile;π    FileDescriptor.Done;π  end;ππProcedure LabeledFile.OpenFile;π  beginπ    FileDescriptor.OpenFile;π    if IsOpen thenπ        ReadHeader;π  end;ππProcedure LabeledFile.CloseFile;π  beginπ    {$I-}π    if IsOpen thenπ      beginπ        if SoftPut and (CurRec <> -1) thenπ            PutRecord(CurRec);π        Header.Val := 0;π        WriteHeader;π        CurRec := -1;π      end;π    FileDescriptor.CloseFile;π    {$I+}π  end;ππProcedure LabeledFile.ReadHeader;π  Varπ    Result : Word;π  beginπ    {$I-}π    Seek(Fpt,0);π    if IoResult = 0 thenπ      beginπ        BlockRead(Fpt,Header,HeaderSize,Result);π        if (Result <> HeaderSize) or (IoResult <> 0) thenπ            {Error Routine};π      end;π    {$I+}π  end;ππProcedure LabeledFile.WriteHeader;π  Varπ    Result : Word;π  beginπ    {$I-}π    Seek(Fpt,0);π    if IoResult = 0 thenπ      beginπ        BlockWrite(Fpt,Header,HeaderSize,Result);π        if (Result <> HeaderSize) or (IoResult <> 0) thenπ            {Error Routine};π      end;π    {$I+}π  end;ππProcedure LabeledFile.AddRecord;π  Varπ    TmpRec : Pointer;π    Result : Word;π    Next   : LongInt;π  beginπ    {$I-}π    if Header.MRD <> 0 thenπ      beginπ        GetMem(TmpRec,RecordSize);π        Seek(Fpt,HeaderSize + (Header.MRD - 1) * RecordSize);π        if IoResult = 0 thenπ          beginπ            BlockRead(Fpt,TmpRec^,RecordSize,Result);π            if (Result <> RecordSize) or (IoResult <> 0) thenπ                {Error Routine};π            Next := LongInt(TmpRec^);π            PutRecord(Header.MRD);π            Header.MRD := Next;π            Header.Act := Header.Act + 1;π          end;π        FreeMem(TmpRec,RecordSize);π      endπ    elseπ      beginπ        PutRecord(Header.Eof);π        Header.Eof := Header.Eof + 1;π        Header.Act := Header.Act + 1;π      end;π    WriteHeader;π    {$I+}π  end;ππProcedure LabeledFile.DelRecord(Rec : LongInt);π  Varπ    TmpRec : Pointer;π    Result : Word;π  beginπ    {$I-}π    GetMem(TmpRec,RecordSize);π    Seek(Fpt,HeaderSize + (Rec - 1) * RecordSize);π    if IoResult = 0 thenπ      beginπ        BlockRead(Fpt,TmpRec^,RecordSize,Result);π        LongInt(TmpRec^) := Header.MRD;π        BlockWrite(Fpt,TmpRec^,RecordSize,Result);π        if (Result <> RecordSize) or (IoResult <> 0) thenπ           {Error Routine};π        Header.MRD := Rec;π        Header.Act := Header.Act - 1;π        WriteHeader;π      end;π    {$I+}π  end;ππ{---------------------------------------------------------------------------}ππConstructor DetailFileDetail.Init(Nam : String; Size : Word; Buff : Pointer;πPut : Boolean);π  beginπ    if Size < 12 thenπ      beginπ        WriteLn('Detail File Records must be 12 Bytes or more');π        Fail;π      end;π    LabeledFile.Init(Nam,Size,Buff,Put);π  end;ππProcedure   DetailFileDetail.LinkChain(MR, Last, Curr : LongInt);π  Varπ    Hdr : DetailHeaderPtr;π  beginπ    Hdr := RecordPtr;π    if Last <> 0 thenπ      beginπ        GetRecord(Last);π        Hdr^.Next := Curr;π        PutRecord(Last);π      end;π    GetRecord(Curr);π    Hdr^.Prev := Last;π    Hdr^.Master := MR;π    Hdr^.Next := 0;π    PutRecord(Curr);π  end;ππProcedure   DetailFileDetail.DelinkChain(Rec : LongInt);  Varπ    Hdr : DetailHeaderPtr;π    Tmp : LongInt;π  beginπ    Hdr := RecordPtr;π    GetRecord(Rec);π    if Hdr^.Next <> 0 thenπ      beginπ        Tmp := Hdr^.Prev;π        GetRecord(Hdr^.Next);π        Hdr^.Prev := Tmp;π        PutRecord(CurRec);π        GetRecord(Rec);π      end;π    if Hdr^.Prev <> 0 thenπ      beginπ        Tmp := Hdr^.Next;π        GetRecord(Hdr^.Prev);π        Hdr^.Next := Tmp;π        PutRecord(CurRec);π        GetRecord(Rec);π      end;π    Hdr^.Master := 0;π    Hdr^.Next := 0;π    Hdr^.Prev := 0;π    PutRecord(Rec);π  end;ππ{---------------------------------------------------------------------------}ππConstructor DetailFileMaster.Init(Nam : String; Size : Word; Buff : Pointer;πPut : Boolean);π  beginπ    if Size < 8 thenπ      beginπ        WriteLn('Master File Records must be 8 Bytes or more');π        Fail;π      end;π    LabeledFile.Init(Nam,Size,Buff,Put);π  end;ππProcedure   DetailFileMaster.LinkDetail(DF : DetailFileDetailPtr);π  Varπ    Hdr : MasterHeaderPtr;π  beginπ    Hdr := RecordPtr;π    DF^.AddRecord;π    DF^.LinkChain(CurRec,Hdr^.Last,DF^.CurRec);π    Hdr^.Last := DF^.CurRec;π    if Hdr^.First = 0 then Hdr^.First := DF^.CurRec;π    PutRecord(CurRec);π  end;ππProcedure   DetailFileMaster.DelinkDetail(DF : DetailFileDetailPtr; DR :πLongInt);π  Varπ    Hdr : MasterHeaderPtr;π  beginπ    Hdr := RecordPtr;π    DF^.GetRecord(DR);π    if Hdr^.Last = DR thenπ        Hdr^.Last := DetailHeader(DF^.RecordPtr^).Prev;π    if Hdr^.First = DR thenπ        Hdr^.First := DetailHeader(DF^.RecordPtr^).Next;π    DF^.DelinkChain(DR);π    PutRecord(CurRec);π  end;ππProcedure   DetailFileMaster.GetFirst(DF : DetailFileDetailPtr);π  Varπ    Hdr : MasterHeaderPtr;π  beginπ    Hdr := RecordPtr;π    if Hdr^.First = 0 thenπ      beginπ        FillChar(DF^.RecordPtr^,DF^.RecordSize,#0);π        DF^.CurRec := -1;π        Exit;π      end;π    DF^.GetRecord(Hdr^.First);π  end;ππProcedure   DetailFileMaster.GetLast(DF : DetailFileDetailPtr);π  Varπ    Hdr : MasterHeaderPtr;π  beginπ    Hdr := RecordPtr;π    if Hdr^.Last = 0 thenπ      beginπ        FillChar(DF^.RecordPtr^,DF^.RecordSize,#0);π        DF^.CurRec := -1;π        Exit;π      end;π    DF^.GetRecord(Hdr^.Last);π  end;ππProcedure   DetailFileMaster.GetNext(DF : DetailFileDetailPtr);π  Varπ    Hdr : DetailHeaderPtr;π  beginπ    Hdr := DF^.RecordPtr;π    if Hdr^.Next = 0 thenπ      beginπ        FillChar(DF^.RecordPtr^,DF^.RecordSize,#0);π        DF^.CurRec := -1;π        Exit;π      end;π    DF^.GetRecord(Hdr^.Next);π  end;ππProcedure   DetailFileMaster.GetPrev(DF : DetailFileDetailPtr);π  Varπ    Hdr : DetailHeaderPtr;π  beginπ    Hdr := DF^.RecordPtr;π    if Hdr^.Prev = 0 thenπ      beginπ        FillChar(DF^.RecordPtr^,DF^.RecordSize,#0);π        DF^.CurRec := -1;π        Exit;π      end;π    DF^.GetRecord(Hdr^.Prev);π  end;ππ{---------------------------------------------------------------------------}ππbeginπend.ππ                      6      05-28-9313:54ALL                      SWAG SUPPORT TEAM        PTR-MEM.PAS              IMPORT              5           Program Test_Pointers;ππTypeπ  Array_Pointer = ^MyArray;π  MyArray = Array[1..10] of String;ππVarπ  MyVar : Array_Pointer;ππbeginπ  Writeln('Memory beFore initializing Variable : ',MemAvail);ππ  New(MyVar);ππ  Writeln('Memory after initializiation : ',MemAvail);ππ  MyVar^[1] := 'Hello';π  MyVar^[2] := 'World!';ππ  Writeln(MyVar^[1], ' ', MyVar^[2]);ππ  Dispose(MyVar);ππ  Writeln('Memory after Variable memory released : ',MemAvail);πend.π                                                                       7      05-28-9313:54ALL                      SWAG SUPPORT TEAM        PTRARRAY.PAS             IMPORT              13          DS> Hi, I've recently encountered a problem With not having enough memoryπDS> to open a large sized Array [ie: 0..900].  Is there any way toπDS> allocate more memory to the Array as to make larger ArraysππArray of what?  if the total size of the Array (i.e. 901 *πsizeof(whatever_it_is_you're_talking_about)) is less than 64K, it's a snap.πRead your dox on Pointers and the heap.  You'll end up doing something likeπthis:ππTypeπ  tWhatever : whatever_it_is_you're_talking_about;π  tMyArray : Array[0..900] of tWhatever;π  tPMyArray : ^MyArray;ππVarπ  PMyArray : tPMyArray;ππbeginπ  getmem(PMyArray,sizeof(tMyArray));ππ  { now access your Array like this:π    PMyArray^[IndexNo] }ππif your Array is >64K, you can do something like this:ππTypeπ  tWhatever : whatever_it_is_you're_talking_about;π  tPWhatever : ^tWhatever;ππVarπ  MyArray : Array[0..900] of tPWhatever;π  i : Word;ππbeginπ  For i := 0 to 900 doπ    getmem(MyArray[i],sizeof(tWhatever));ππ  { now access your Array like this:π    MyArray[IndexNo]^ }ππif you don't have enough room left in your data segment to use this latterπapproach (and I'll bet you do), you'll just need one more level of indirection.πDeclare one Pointer in the data segment that points to the Array of Pointers onπthe heap, which in turn point to your data.ππif you're a beginner, this may seem impossibly Complex (it did to me), but keepπat it and it will soon be second nature.π                                                                                                                          8      05-28-9313:54ALL                      SWAG SUPPORT TEAM        TREEHITE.PAS             IMPORT              7           {πAuthors: Chet Kress and Jerome Tonnesonππ>Help !!! I need a Function or Procedure in standard pascal that willπ>calculate the height of a binary tree. It must be able to calculate theπ>height of the tree if the tree is either balanced, unbalanced or full.π>The Procedure must be recursive.ππHere are the only two Functions you will need.π}ππFunction Max(A, B : Integer) : Integer;πbegin {Max}π  If A > B thenπ    Max := A;π  elseπ    Max := B;πend; {Max}ππFunction Height (Tree : TreeType) : Integer;πbegin {Height}π  If Tree = Nil thenπ    Height := 0π  elseπ    Height := Max(Height(Tree^.Right), Height(Tree^.Left)) + 1;πend; {Height}π